package priv.yiyuan.example.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 文档组件类
 * <p>
 * 组合模式 组合节点
 *
 * @author YiYuan
 * @data 2025/8/28
 * @apoNote
 */
public class DocumentComposite implements DocumentComponent {

    private List<DocumentComponent> children = new ArrayList<>();

    public void add(DocumentComponent component) {
        children.add(component);
    }

    public void remove(DocumentComponent component) {
        children.remove(component);
    }

    public DocumentComponent get(int i) {
        return children.get(i);
    }

    @Override
    public void render() {
        for (DocumentComponent component : children) {
            component.render();
        }
    }

}
